package com.nfzm.service.impl;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import com.alibaba.fastjson2.JSONObject;
import com.nfzm.service.NfzmArticlePicService;
import com.nfzm.dao.NfzmArticlePicDao;
import com.nfzm.entity.NfzmArticlePic;
/**
 * NfzmArticlePic的服务接口的实现类
 * 
 * @author 
 *
 */
@Service
public class NfzmArticlePicServiceImpl implements NfzmArticlePicService {
	private final Logger LOG = LogManager.getLogger(this.getClass());

	@Autowired
	private NfzmArticlePicDao nfzmArticlePicDao;
	// TODO 当你看到这个方法时你应该创建一个工具类做通用的方法,定义自己的返回格式化
	private static final int C200 = 200;
	private static final int C412 = 412;
	public String resultFormat(int code, Object data) {
		JSONObject result = new JSONObject();
		result.put("code", code);
		if (data != null) {
			result.put("data", data);
		}
		return result.toJSONString();
	}

	@Override
	public List<NfzmArticlePic> find(NfzmArticlePic value) {
		//TODO这里可以做通过Assist做添加查询
		List<NfzmArticlePic> result = nfzmArticlePicDao.selectNfzmArticlePicByObj(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行获取NfzmArticlePic数据集-->结果:", result);
		}
		return result;
	}

	@Override
	public int saveNotNull(NfzmArticlePic value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将NfzmArticlePic中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
			return -1;
		}
		if(value.getArticleId() == null  ){
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将NfzmArticlePic中属性值不为null的数据保存到数据库-->失败:存在不能为空的空值");
			}
			return -1;
		}
		int result = nfzmArticlePicDao.insertNotNullNfzmArticlePic(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行将NfzmArticlePic中属性值不为null的数据保存到数据库-->结果:", result);
		}
		return result;
	}

	@Override
	public int saveBatch(List<NfzmArticlePic> pics) {
		return nfzmArticlePicDao.insertNfzmArticlePicByBatch(pics);
	}


}